package com.tczs.web.action;

import com.alibaba.fastjson.JSONObject;
import com.tczs.web.config.NeedLogin;
import com.tczs.web.service.DatabaseService;
import com.tczs.web.util.JSONUtil;
import io.netty.util.internal.StringUtil;
import org.apache.log4j.Logger;

/**
 * 有关数据库操作
 */
public class DatabaseAction {

    private static Logger logger = Logger.getLogger(DatabaseAction.class);

    /**
     * 查找所有数据库
     * @param method 请求方法
     * @return
     */
    @NeedLogin
    public JSONObject findAllDatabase(String method){
        logger.info("entry findAllDatabase.........");
        DatabaseService databaseService = new DatabaseService();
        return databaseService.findAllDatabase();
    }

    /**
     * 创建数据库
     * @param method 请求方法
     * @return
     */
    @NeedLogin
    public JSONObject createDatabase(String method,String databaseName){
        logger.info("entry createDatabase.........");
        DatabaseService databaseService = new DatabaseService();
        return databaseService.createDatabase(databaseName);
    }


    /**
     * 查询数据
     * @param method
     * @param databaseName
     * @param tableName
     * @return
     */
    @NeedLogin
    public JSONObject findData(String method,String databaseName,String tableName){
        logger.info("entry findData.........");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",200);
        if("test".equals(databaseName)){
            jsonObject.put("data",new String[]{"User","Order","Goods"});
        }
        if("test2".equals(databaseName)){
            jsonObject.put("data",new String[]{"User2","Order2","Goods2"});
        }
        return jsonObject;
    }

}
